package controller

import (
	"fileshare/controller/server"
	"fileshare/controller/tools"
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
* @program: fileshare
*
* @description:
*
* @author: Koco.Allien
*
* @create: 2020-04-05 19:14
**/
func RegistController(c *gin.Context) {
	aid := tools.GatQuery(c, "active", 0)
	data, _, _ := tools.StartDate(c, "注册", aid)

	c.HTML(http.StatusOK, "regist.html", data)
}

func RegistControllerPost(c *gin.Context) {
	aid := tools.GatQuery(c, "active", 0)
	data, _, _ := tools.StartDate(c, "注册", aid)
	account := c.PostForm("account")
	passwd1 := c.PostForm("passwd1")
	passwd2 := c.PostForm("passwd2")
	if passwd1 != passwd2 || account == "" || passwd2 == "" {
		data["error"] = "两次密码不正确"
	} else {
		if server.CreateUser(account, passwd1) {
			data["error"] = "注册成功:" + account
		} else {
			data["error"] = "账户已经注册过..."
		}
	}
	c.HTML(http.StatusOK, "regist.html", data)

}
